#{extends 'ApiDoc/base.html'/}

<script>
    window.invoker = '${clazz.getCanonicalName()}.${method.getName()}';
    $(function(){
        activeMenu(window.invoker);
    });
</script>



<link rel="stylesheet" type="text/css"
      href="#{href '/public/apidoc/layout/res_iframe.css'/}"/>

<link rel="stylesheet" href="#{href '/public/apidoc/view.css'/}">
<script src="#{href '/public/apidoc/view.js'/}"></script>

<div class="page_doc">
    <div class="main_hd"><h2 id="title">${clazz.getApiName()} - ${method.getApiActionName()}</h2></div>
    <div class="main_bd">
        <div class="article_box">
            <div class="inner">
                #{apistats /}
                <div id="content" class="news_content">
                    %{
                        apiAction = method.getApiAction()
                        apiService = clazz.getApiService()
                    }%
                    <!-- 1. 接口文字说明 -->
                    <h2>1. 概要说明</h2>
                    #{if apiAction.desc()}
                    <p class="p">
                        ${apiAction.desc().nl2br()}
                    </p>
                    #{/if}
                    #{if apiService.author()}
                    <p class="p">
                        维护者：${apiService.author()}
                    </p>
                    #{/if}

                    <!-- 2. 接口调用说明 -->
                    <h2>2. 调用说明</h2>
                    <div>
                        <div>http请求方式：${apiAction.requestMethod()}</div>
                        <div class="code-text">${method.getActionAsUrl(clazz)}</div>
                    </div>
#{if isDuppApi}
                    <br>
                    <div>
                        <div>Dupp接口：</div>
                        <pre class="code-text">
/**
 * ${clazz.getApiName()} - ${method.getApiActionName()}
 * ${apiAction.desc()}
 * @link @@{ApiDoc.viewApi(clazz.getName(), method.getName())}
 */
@Dupp("${method.getActionAsSubUrl(clazz)}")
JSONObject ${method.getName()}(
#{list items: method.getApiActionParam(), as: 'param'}%{apiParam = param.getApiActionParamAnnotation()}%#{if apiParam}
     //${apiParam.name()} ${apiParam.note()} [${apiParam.isRequire() ? '必填': '选填'}] ${apiParam.isDeprecated()? '[已废弃]':''}
     @Param("${apiParam.value()}") ${param.getType().getSimpleName()} ${apiParam.value()}${param_isLast? '':','}
#{/if}#{/list}
);</pre>
                    </div>

<div class="test-form">
    <div>测试接口：</div>
    <form action="@{ApiDoc.executeDupp}" id="test-dupp-form" enctype ="multipart/form-data" method="POST" onsubmit="return false;">
        <input type="hidden" name="dupp_url" value="${method.getActionAsUrl(clazz)}">
        <table>
            <thead>
                <tr>
                    <th>参数</th>
                    <th>数据</th>
                    <th>备注</th>
                </tr>
            </thead>
            <tbody>
            #{list items: method.getApiActionParam(), as: 'param'}
            %{apiParam = param.getApiActionParamAnnotation()}%
            #{if apiParam}
            <tr>
                <td class="code-text">
                    ${apiParam.isRequire() ? '*': ''}
                    #{if apiParam.isDeprecated()}
                        <span class="deprecated">${apiParam.value()}</span>
                    #{/if}
                    #{else}
                        ${apiParam.value()}
                    #{/else}
                </td>
                <td>
                    #{if param.getType().getSimpleName() == 'String' && apiParam.isBlob()}
                    <textarea class="J-input" name="${apiParam.value()}" rows="5" placeholder="${apiParam.name()}"></textarea>
                    #{/if}
                    #{elseif param.getType().getSimpleName() == 'File'}
                    <input class="J-input" type="file" name="${apiParam.value()}">
                    #{/elseif}
                    #{elseif !apiParam.enumType().equals(apidocs.NotEnum.class)}
                    <select class="J-input" name="${apiParam.value()}">
                        <option value="">不填</option>
                        #{list items: apiParam.enumType(), as:'e'}
                        <option value="${e.value}">(${e.value})${e.description}</option>
                        #{/list}
                    </select>
                    #{/elseif}
                    #{else}
                    <input class="J-input" type="text" placeholder="${apiParam.name()}" name="${apiParam.value()}">
                    #{/else}
                </td>
                <td>${apiParam.name()} ${apiParam.note()}</td>
            </tr>
            #{/if}
            #{/list}
            </tbody>
        </table>
        <pre id="output" class="hide code-text"></pre>
        <div class="actions">
            <button class="primary-btn" id="submit-btn" type="button">提交测试</button>
        </div>
    </form>
</div>
#{/if}

                    <!-- 3. 接口参数说明 -->
                    <h2>3. 参数说明</h2>
                    <table class="table">
                        <thead>
                        <tr>
                            <th>参数</th>
                            <th>备注</th>
                            <th>类型</th>
                            <th>必填</th>
                        </tr>
                        </thead>
                        <tbody>
                        #{list items: method.getApiActionParam(), as: 'param'}
                        %{apiParam = param.getApiActionParamAnnotation()}%
                        #{if apiParam}
                        <tr>
                            <td class="code-text">
                                #{if apiParam.isDeprecated()}
                                <span class="deprecated">${apiParam.value()}</span>
                                #{/if}
                                #{else}
                                ${apiParam.value()}
                                #{/else}
                            </td>
                            <td>
                                #{if apiParam.name()}
                                    ${apiParam.name()}
                                #{/if}
                                #{ifnot apiParam.enumType().equals(apidocs.NotEnum.class)}
                                    说明：
                                    #{list items: apiParam.enumType(), as:'e'}
                                        ${e.value} ${e.description} ${e_isLast? '':', '}
                                    #{/list}
                                #{/ifnot}
                                #{if apiParam.note()}
                                    ，${apiParam.note()}
                                #{/if}
                            </td>
                            <td class="code-text">
                                #{if param.isParameterized()}
                                <a href="/@apidoc/class/${param.getParameterized().getName()}">${param.getParameterized().getSimpleName()}</a>[]
                                #{/if}
                                #{else}
                                    ${param.getParameterizedType().getSimpleName()}
                                #{/else}
                            </td>

                            <td>${apiParam.isRequire() ? '必填': '选填'}</td>
                        </tr>
                        #{/if}
                        #{/list}
                        </tbody>
                    </table>

                    <!-- 4. 接口返回说明 -->
                    <h2>4. 返回说明</h2>
                    %{apiResult = apiAction.resultType().getApiResult()}%

                    #{if apiAction.resultNote()}
                    <p>说明：${apiAction.resultNote()}</p>
                    #{/if}

                    #{if apiAction.resultType().isApiResultPrimitive()}
                    <p>结构：${apiAction.isList() ? '数组':'单个对象'}，类型：${apiAction.resultType().getApiResultPrimitiveName()}</p>
                    #{/if}
                    #{else}
                    <p>
                        结构：${apiAction.isList() ? '数组':'单个对象'}
                        #{if apiResult}
                        类型：${apiResult.value()}
                        #{/if}
                    </p>

                    #{if apiResult && apiResult.note()}
                    <p>
                        说明：${apiAction.resultNote()} ${apiResult.note()}
                    </p>
                    #{/if}
                    <table class="table">
                        <thead>
                        <tr>
                            <th>字段</th>
                            <th>名称</th>
                            <th>类型</th>
                            <th>备注</th>
                        </tr>
                        </thead>
                        <tbody>
                        #{list items: apiAction.resultType().getApiResultField(), as: 'field'}
                        %{resultField = field.getApiResultField()}%
                        #{if resultField}
                        <tr>
                            <td class="code-text">${field.getName()}</td>
                            <td>${resultField.value()}</td>
                            <td>
                                #{fieldLink field:field/}
                            </td>
                            <td>
                                ${resultField.note()}
                                #{ifnot resultField.enumType().equals(apidocs.NotEnum.class)}
                                    说明：
                                    #{list items: resultField.enumType(), as:'e'}
                                        ${e.value} ${e.description} ${e_isLast? '':', '}
                                    #{/list}
                                #{/ifnot}

                            </td>
                        </tr>
                        #{/if}
                        #{else}
                        <tr>
                            <td class="code-text">${field.getName()}</td>
                            <td>${field.getName()}</td>
                            <td>
                                #{fieldLink field:field/}
                            </td>
                            <td>-</td>
                        </tr>
                        #{/else}
                        #{/list}
                        </tbody>
                    </table>
                    #{/else}
                    <!--返回接口的源代码-->
                    #{ifnot apiAction.resultType().isApiResultPrimitive()}
                        <h2>Java Class</h2>
                        <pre class="code-text">
/*
 * ${apiResult?.value()}
 */
public class ${apiAction.resultType().simpleName}{
                            
#{list items: apiAction.resultType().getApiResultField(), as: 'field'}
%{resultField = field.getApiResultField()}%
    #{if resultField}
//${resultField.value()} ${resultField.note()} #{ifnot resultField.enumType().equals(apidocs.NotEnum.class)} 说明： #{list items: resultField.enumType(), as:'e'} ${e.value} ${e.description} ${e_isLast? '':', '} #{/list} #{/ifnot}
    #{/if}

    public ${field.type.simpleName} ${field.name};

#{/list}
}
                        </pre>
                    #{/ifnot}
                    <!-- 5. 接口注意说明 -->
                    #{if apiAction.note()}
                    <h2>5. 接口注意说明</h2>
                    <p class="p">
                        ${apiAction.note()}
                    </p>
                    #{/if}
                </div>
            </div>
        </div>
    </div>

</div>